package lms.utils;


import lms.entity.Book;
import lms.entity.Reader;
import lms.entity.ReaderType;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

/**
 * @description:
 * @author: Grape_Pip
 * @time: 2021/06/22
 */
public class ReaderRowMapper implements RowMapper<Reader> {

    @Override
    public Reader mapRow(ResultSet resultSet, int i) throws SQLException {
//        读者基本信息
        int rid = resultSet.getInt("rid");
        String rName = resultSet.getString("rname");
        String rGender = resultSet.getString("rgender");
        String rTel = resultSet.getString("rtel");
        String rMajor = resultSet.getString("rmajor");
        String  rType= resultSet.getString("rtype");
        Date  rRegisTime= resultSet.getDate("rregistime");

//        读者类型信息
        String rTypeName=resultSet.getString("rtype");
        int limit=resultSet.getInt("rtlimit");

        Reader reader = new Reader();
        ReaderType readerType=new ReaderType();

        readerType.setrType(rTypeName);
        readerType.setLimit(limit);

        reader.setReaderId(rid);
        reader.setReaderName(rName);
        reader.setReaderGender(rGender);
        reader.setReaderTel(rTel);
        reader.setReaderMajor(rMajor);
        //读者类型放入
        reader.setReaderType(readerType);
        reader.setReaderRegisDate(rRegisTime);


        return reader;
    }
}
